<?php


namespace app\lib;


class Sign
{
    public static function create($secret,$data){
        foreach ($data as $index => $datum) {
            if ($datum==''){
                unset($data[$index]);
            }
        }

        ksort($data);
        $str=md5(urldecode(http_build_query($data)).$secret);
        return $str;
    }

    public static function check($sign,$secret,$data){
        unset($data['sign']);
        $newSign=self::create($secret,$data);

        if ($newSign===$sign){
            return true;
        }else{
            return false;
        }
    }
}